﻿<%@page import="com.mysql.jdbc.StringUtils"%>
<%@ page contentType="text/html; charset=utf-8" language="java" import="java.util.*,java.io.*,java.sql.*" errorPage="" %>
<%@ page import="com.zhuozhengsoft.ZSOfficeX.*, com.hnjowe.util.*, com.union.core.doc.model.*"%>
<%@ page import="com.union.core.doc.service.*"%>
<%request.setCharacterEncoding("utf-8");%>
<%response.setCharacterEncoding("utf-8");%>
<%@page pageEncoding="utf-8"%>
<%
	String docid = request.getParameter("docid");
	String template_id = request.getParameter("template_id");
	OfficialDoc officialDoc = ComUtil.getOfficialDocService().query(Long.parseLong(docid));
	DocTemplate docTemplate = ComUtil.getOfficialDocService().queryTemplate(Long.parseLong(template_id));

	SaveDocObj   SaveObj  = new SaveDocObj(request, response);
	//SaveObj.FileName; //获取文件名
	//SaveObj.FileExtName;  //获取文件扩展名
	//SaveObj.FileSize;  //获取文件大小，以字节为单位
	//SaveObj.getFileBytes();  //获取文件二进制流，可以保存到数据库字段
	
	String saveFileName = officialDoc.getDoc_file_name();
	if(StringUtils.isNullOrEmpty(saveFileName)){
		saveFileName = ComUtil.genFileId();
		String fileext = SaveObj.FileExtName;
		saveFileName = saveFileName + fileext;
		String saveFilePath = ComUtil.DOC_UPLOAD_DIR + saveFileName;
		
		//没有保存过则保存
		officialDoc.setDoc_file_name(saveFileName);
		officialDoc.setDoc_file_path(saveFilePath);
		ComUtil.getOfficialDocService().edit(officialDoc);
	}

	try{
		SaveObj.saveToFile(request.getRealPath("/") + ComUtil.DOC_UPLOAD_DIR + saveFileName);  // saveToFile 的参数是文档的物理绝对路径，例如: “D:\\doc\\abc.doc”
		SaveObj.returnOK();
	}
	finally {
		SaveObj.close();
	}
		
	
%>